package yhp.com.zijie.dao.impl;

import yhp.com.zijie.dao.MiddleDao;
import yhp.com.zijie.util.DBUtils;

import java.sql.PreparedStatement;
import java.sql.SQLException;

public class MiddleDaoImpl extends DBUtils implements MiddleDao {


    @Override
    public int insertMiddle(int roleid, String[] ids) {

        int k=0;
        try {
            String sql = "insert into middle values(null,?,?)"; //角色id ， 菜单id
            //批量新增
            pps = getPps(sql);

            for (String id : ids) {
                pps.setInt(1 , roleid);
                pps.setString(2,id);
                pps.addBatch();
            }
            pps.executeBatch();
            k=1;
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            closeAll();
        }

        return k;
    }
}
